//
//  MAUserInfoTool.m
//  meiang_edu
//
//  Created by hfcb on 2018/8/2.
//  Copyright © 2018年 com.meiang.meiang_edu. All rights reserved.
//

#import "MAUserInfoTool.h"

#define FILEPATH [[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:@"account.archiver"]

@implementation MAUserInfoTool

/** 存储用户信息 */
+ (void)saveUserInfo:(MAUserInfo *)userinfo {
    DLog(@"%@",FILEPATH);
    [NSKeyedArchiver archiveRootObject:userinfo toFile:FILEPATH];
}

/** 获取用户信息 */
+ (MAUserInfo *)userinfo {
    MAUserInfo *userinfo = [NSKeyedUnarchiver unarchiveObjectWithFile:FILEPATH];
    if (userinfo == nil) {
        userinfo = [[MAUserInfo alloc] init];
    }
    return userinfo;
}

/** 删除用户信息 */
+ (void)deleteUserInfo {
    NSFileManager* fileManager = [NSFileManager defaultManager];
    BOOL blHave = [[NSFileManager defaultManager] fileExistsAtPath:FILEPATH];
    if (!blHave) {
        return ;
    } else {
        BOOL blDele = [fileManager removeItemAtPath:FILEPATH error:nil];
        if (blDele) {
            DLog(@"删除成功");
        }else {
            DLog(@"删除失败");
        }
    }
}
@end
